import torch.nn.functional as F
from ..registry import LOSSES
from .base import BaseWeightedLoss


@LOSSES.register()
class CrossEntropyLoss(BaseWeightedLoss):
    """Cross Entropy Loss."""
    def _forward(self, score, labels, smoothing=0.0,**kwargs):
        """Forward function.
        Args:
            score (paddle.Tensor): The class score.
            labels (paddle.Tensor): The ground truth labels.
            kwargs: Any keyword argument to be used to calculate
                CrossEntropy loss.
        Returns:
            loss (paddle.Tensor): The returned CrossEntropy loss.
        """
        loss = F.cross_entropy(score, labels, label_smoothing=smoothing, **kwargs)
        return loss
